package com.snape.utils;

import com.snape.dao.RoomDao;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Created by liuqingcan_snape on 2017/4/8.
 */
public class PageLimitUtils {
    static final int countNumber = 10;
//    @Autowired
//    RoomDao roomDao;

    public int countStartNumber(int pageNumber,int postCountNumber,int realDbSum) throws Exception{
        int coNumber = countNumber;
        if (postCountNumber > 0){
            coNumber = postCountNumber;
        }

        int number = 0;
        int startSum = pageNumber * coNumber;
//        int realDbSum = roomDao.selectCountRoomByCategoryId(cateId);
        if (startSum > realDbSum){
            number = realDbSum;//数据已经被查询完
        }else {
            number = startSum;
        }
        return number;
    }

    public int countEndNumber(int pageNumber,int postCountNumber,int realDbSum) throws Exception{
        int cNumber = countNumber;
        if (postCountNumber > 0){
            cNumber = postCountNumber;
        }

        int number = 0;
        int startSum = pageNumber * cNumber;
        int endSum = (pageNumber+1) * cNumber;
//        int realDbSum = roomDao.selectCountRoomByCategoryId(cateId);
        if (startSum > realDbSum){
            number = 0;//数据已经被查询完
        }else if (endSum > realDbSum){
            number = endSum - realDbSum;//查询不够10条数据
        }else if (realDbSum > endSum){
            number = cNumber;
        }
        return number;
    }


}
